<template>
  <div>
    <el-row :gutter="20">
      <el-col :span="6">
        <el-card :body-style="{ padding: '0px' }">
          <img :src="recommendFrom[0].picture" class="image">
          <div style="padding: 14px;">
            <span>{{ recommendFrom[0].dishName }}</span>
            <div class="bottom clearfix">
              <time class="time">{{ currentDate }}</time>
              <el-button type="text" class="button" @click="toFoodPage">点我试试</el-button>
            </div>
          </div>
        </el-card>
      </el-col>
      <el-col :span="6">
        <el-card :body-style="{ padding: '0px' }">
          <img :src="recommendFrom[1].picture" class="image">
          <div style="padding: 14px;">
            <span>{{ recommendFrom[1].dishName }}</span>
            <div class="bottom clearfix">
              <time class="time">{{ currentDate }}</time>
              <el-button type="text" class="button" @click="toFoodPage">点我试试</el-button>
            </div>
          </div>
        </el-card>
      </el-col>
      <el-col :span="6">
        <el-card :body-style="{ padding: '0px' }">
          <img :src="recommendFrom[2].picture" class="image">
          <div style="padding: 14px;">
            <span>{{ recommendFrom[2].dishName }}</span>
            <div class="bottom clearfix">
              <time class="time">{{ currentDate }}</time>
              <el-button type="text" class="button" @click="toFoodPage">点我试试</el-button>
            </div>
          </div>
        </el-card>
      </el-col>
      <el-col :span="6">
        <el-card :body-style="{ padding: '0px' }">
          <img :src="recommendFrom[3].picture" class="image">
          <div style="padding: 14px;">
            <span>{{ recommendFrom[3].dishName }}</span>
            <div class="bottom clearfix">
              <time class="time">{{ currentDate }}</time>
              <el-button type="text" class="button" @click="toFoodPage">点我试试</el-button>
            </div>
          </div>
        </el-card>
      </el-col>
    </el-row>


  </div>


</template>

<script>
import {getFoodsInfo} from "@/api";

export default {
  name: "recommend",
  data() {
    return {
      currentDate:'',
      recommendFrom:[]
    };
  },
  mounted() {
    this.getNowTime();
    this.getRecommendForm()

  },
  methods: {
    getNowTime(){
      const yy = new Date().getFullYear()
      const MM = (new Date().getMonth() + 1) < 10 ? '0' + (new
      Date().getMonth() + 1) : (new Date().getMonth() + 1)
      const dd = new Date().getDate() < 10 ? '0' + new Date().getDate() : new
      Date().getDate()
      const HH = new Date().getHours() < 10 ? '0' + new Date().getHours() : new
      Date().getHours()
      const mm = new Date().getMinutes() < 10 ? '0' + new Date().getMinutes() :
        new Date().getMinutes()
      const ss = new Date().getSeconds() < 10 ? '0' + new Date().getSeconds() :
        new Date().getSeconds()
      this.currentDate = yy + '-' + MM + '-' + dd ;
    },
    toFoodPage() {
      this.$router.push('/Food')
    },
    getRecommendForm(){
      getFoodsInfo().then(res=>{
        for(let j=0;j<4;j++){
          let i = Math.floor(Math.random() * 51 )
          this.recommendFrom[j]=res.data[i]
        }
      })
    }
  }

}
</script>

<style>
.time {
  font-size: 13px;
  color: #999;
}

.bottom {
  margin-top: 13px;
  line-height: 12px;
}

.button {
  padding: 0;
  float: right;
}

.image {
  width: 100%;
  display: block;
  height: 250px;
}

.clearfix:before,
.clearfix:after {
  display: table;
  content: "";
}

.clearfix:after {
  clear: both
}
</style>
